<?
$pagename=LA_PICTURE_GALLERY;
include_once("header_inc.php");
$tplPbrowse=new TplLoad;
$offset=getParam("offset",0);
if ($set_pg_login_need==1)
	check_valid_user("$la_mem_gal");

if ($set_validation == 1) { $val_string = " AND ad_is_validated = 1 AND ad_enabled = 1"; } else { $val_string = " AND ad_enabled = 1"; }

$option_list=getCategoriesDD(getParamInt("catid",""),2);
$tplPbrowse->assign("option_list", $option_list);

$number_of_ads_per_page = $set_num_browse;
$query = "select $ads_tbl.ad_id,$pic_tbl.id,pic_ad_id,ad_title,$pic_tbl.filename from $pic_tbl,$ads_tbl where $pic_tbl.pic_ad_id = $ads_tbl.ad_id AND main=1 $val_string";
$lAddOnQuery="";

if (getParam("catid",""))
{
	$ltmpChilds=getCategoryChildren(getParamInt("catid",""));
	if ($ltmpChilds)
		$lAddOnQuery.=" AND ad_cat_id IN (". $ltmpChilds . ",". getParamInt("catid",0) .")";
	else
		$lAddOnQuery.=" AND ad_cat_id=". getParamInt("catid",0);
}

	

$query.=$lAddOnQuery;
$result = q($query);
$num_links =  mysql_num_rows($result);

$lNavigation=urlBar($num_links,$number_of_ads_per_page,getParamInt("page",1),getAllParams(array("page")));


$query = "select $ads_tbl.ad_id,$pic_tbl.id,pic_ad_id,ad_title,$pic_tbl.filename from $pic_tbl,$ads_tbl where $pic_tbl.pic_ad_id = $ads_tbl.ad_id AND main=1 $val_string";
$query.=" $lAddOnQuery order by pic_ad_id desc " . $lNavigation["sql_limit"];
$result = q ($query);
$this_screen = mysql_num_rows($result);

$tplPbrowse->assign("this_screen",$this_screen);

$break_counter=0;
while ($row = mysql_fetch_array($result))
{
	$break_counter++;
  	
	$ad_id = $row["pic_ad_id"];
  	$id = $row["pic_ad_id"];
  	$sitetitle = $row["ad_title"];
	$filename = $row["filename"];
	$filename=ereg_replace("tmb2","tmb1",$filename);
	if ($set_image_program==0)
	{
		$lSizeArray=setImageSize($filename,getManualSize("small"),0);
		$lImageList[$i]["w"]=$lSizeArray[0];
		$lImageList[$i]["h"]=$lSizeArray[1];
	}
  	$lImageList[$i]["fancy_opentable"]=cornerTableLayout(150,100,1);
  	$lImageList[$i]["filename"]=$filename;
  	$lImageList[$i]["alt"]=htmlspecialchars($sitetitle,ENT_QUOTES); 
  	$lImageList[$i]["id"]=$id;
  	$lImageList[$i]["fancy_closetable"]=cornerTableLayout(150,100,2);
	$lImageList[$i]["link"]=linkDetail($id);
  	
  	$lImageList[$i]["break"]=$break_counter;
  	if ($break_counter==4)
		$break_counter=0;
	$i++;
}
$tplPbrowse->assign("set_gallery_catlist","$set_gallery_catlist");	
$tplPbrowse->assign("set_image_program","$set_image_program");	
$tplPbrowse->assign("image_list",$lImageList);
$tplPbrowse->assign("url_bar",$lNavigation["url_bar"]);
$tplPbrowse->display("picturebrowse.tpl");



function cornerTableLayout($aTableW,$aTableH,$aSection)
{
	if ($aSection==1)
	{
		$retStr.="<table width='$aTableW' cellpadding='0' cellspacing='0' border='0' bgcolor='#CCCCFF'>";
		$retStr.= "<tr><td><img src='layout_images/corner/tl.jpg' alt='' /></td>";
		$retStr.= "<td valign='top'><img src='layout_images/corner/bline.jpg' width='$aTableW' style='height:1px;' class='top'></td>";
		$retStr.= "<td><img src='layout_images/corner/tr.jpg' alt=''></td></tr>";
		$retStr.= "<tr><td align='left'><img src='layout_images/corner/bline.jpg' alt='' height='$aTableH' style='width:1px' /></td>";
		$retStr.= "<td valign='top'>";
		return $retStr;
	}
	
	if ($aSection==2)
	{
		$retStr.= "</td><td align='right'><img src='layout_images/corner/bline.jpg' height='$aTableH' style='width:1px' alt='' /></td></tr>";
		$retStr.= "<tr><td><img src='layout_images/corner/bl.jpg' alt='' /></td>";
		$retStr.= "<td valign='bottom'><img src='layout_images/corner/bline.jpg' alt='' width='$aTableW' style='height:1px;' class='top'></td>";
		$retStr.= "<td><img src='layout_images/corner/br.jpg' alt='' /></td></tr></table>";		
		return $retStr;
	}
}

include_once("footer_inc.php");
?>
